<!DOCTYPE html>
<html lang="en-US" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>千里之行，始于足下</title>
    <meta name="description" content="A VitePress Site">
    <meta name="generator" content="VitePress v1.5.0">
    <link rel="preload stylesheet" href="/assets/style.fRdD-w5h.css" as="style">
    <link rel="preload stylesheet" href="/vp-icons.css" as="style">
    
    <script type="module" src="/assets/app.BP7yagLo.js"></script>
    <link rel="preload" href="/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
    <link rel="modulepreload" href="/assets/chunks/theme.pFBfFTJ0.js">
    <link rel="modulepreload" href="/assets/chunks/framework.veiYM6Mh.js">
    <link rel="modulepreload" href="/assets/column_VueNotes_VUEX.md.HETRXYa7.lean.js">
    <script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
    <script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-e82b0478><!--[--><!--]--><!--[--><span tabindex="-1" data-v-95e4e91c></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-95e4e91c> Skip to content </a><!--]--><!----><header class="VPNav" data-v-e82b0478 data-v-8c670eef><div class="VPNavBar" data-v-8c670eef data-v-f1cc7ac9><div class="wrapper" data-v-f1cc7ac9><div class="container" data-v-f1cc7ac9><div class="title" data-v-f1cc7ac9><div class="VPNavBarTitle has-sidebar" data-v-f1cc7ac9 data-v-706b8a92><a class="title" href="/" data-v-706b8a92><!--[--><!--]--><!--[--><img class="VPImage logo" src="/avatar.png" alt data-v-ee1fe0a4><!--]--><span data-v-706b8a92>千里之行，始于足下</span><!--[--><!--]--></a></div></div><div class="content" data-v-f1cc7ac9><div class="content-body" data-v-f1cc7ac9><!--[--><!--]--><div class="VPNavBarSearch search" data-v-f1cc7ac9><!----></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-f1cc7ac9 data-v-c7dd21cc><span id="main-nav-aria-label" class="visually-hidden" data-v-c7dd21cc> Main Navigation </span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/" tabindex="0" data-v-c7dd21cc data-v-7ca42efb><!--[--><span data-v-7ca42efb>首页</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-c7dd21cc data-v-13cdd73a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-13cdd73a><span class="text" data-v-13cdd73a><!----><span data-v-13cdd73a>前端开发</span><span class="vpi-chevron-down text-icon" data-v-13cdd73a></span></span></button><div class="menu" data-v-13cdd73a><div class="VPMenu" data-v-13cdd73a data-v-782d28ee><div class="items" data-v-782d28ee><!--[--><!--[--><div class="VPMenuLink" data-v-782d28ee data-v-6e301e4f><a class="VPLink link" href="/column/VueNotes/" data-v-6e301e4f><!--[--><span data-v-6e301e4f>vue杂记</span><!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-782d28ee data-v-6e301e4f><a class="VPLink link" href="/column/JavaScript/" data-v-6e301e4f><!--[--><span data-v-6e301e4f>javascript</span><!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-782d28ee data-v-6e301e4f><a class="VPLink link" href="/column/Growing/" data-v-6e301e4f><!--[--><span data-v-6e301e4f>H5C3</span><!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-782d28ee data-v-6e301e4f><a class="VPLink link" href="/column/Growing/" data-v-6e301e4f><!--[--><span data-v-6e301e4f>TS</span><!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-782d28ee data-v-6e301e4f><a class="VPLink link" href="/column/Growing/" data-v-6e301e4f><!--[--><span data-v-6e301e4f>javascript</span><!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-782d28ee data-v-6e301e4f><a class="VPLink link" href="/column/Growing/" data-v-6e301e4f><!--[--><span data-v-6e301e4f>暂无</span><!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-c7dd21cc data-v-13cdd73a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-13cdd73a><span class="text" data-v-13cdd73a><!----><span data-v-13cdd73a>服务端杂记</span><span class="vpi-chevron-down text-icon" data-v-13cdd73a></span></span></button><div class="menu" data-v-13cdd73a><div class="VPMenu" data-v-13cdd73a data-v-782d28ee><div class="items" data-v-782d28ee><!--[--><!--[--><div class="VPMenuLink" data-v-782d28ee data-v-6e301e4f><a class="VPLink link" href="/column/Travel/" data-v-6e301e4f><!--[--><span data-v-6e301e4f>node.js</span><!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-782d28ee data-v-6e301e4f><a class="VPLink link" href="/column/Growing/" data-v-6e301e4f><!--[--><span data-v-6e301e4f>数据库</span><!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-c7dd21cc data-v-13cdd73a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-13cdd73a><span class="text" data-v-13cdd73a><!----><span data-v-13cdd73a>关于我</span><span class="vpi-chevron-down text-icon" data-v-13cdd73a></span></span></button><div class="menu" data-v-13cdd73a><div class="VPMenu" data-v-13cdd73a data-v-782d28ee><div class="items" data-v-782d28ee><!--[--><!--[--><div class="VPMenuLink" data-v-782d28ee data-v-6e301e4f><a class="VPLink link vp-external-link-icon" href="https://gitee.com/akeone" target="_blank" rel="noreferrer" data-v-6e301e4f><!--[--><span data-v-6e301e4f>Gitee</span><!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-782d28ee data-v-6e301e4f><a class="VPLink link vp-external-link-icon" href="https://juejin.cn/user/430664290931799" target="_blank" rel="noreferrer" data-v-6e301e4f><!--[--><span data-v-6e301e4f>掘金</span><!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-f1cc7ac9 data-v-915670bf><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-915670bf data-v-f9f47021 data-v-7a4da74b><span class="check" data-v-7a4da74b><span class="icon" data-v-7a4da74b><!--[--><span class="vpi-sun sun" data-v-f9f47021></span><span class="vpi-moon moon" data-v-f9f47021></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-f1cc7ac9 data-v-561d04be data-v-c9628203><!--[--><a class="VPSocialLink no-icon" href="https://github.com/vuejs/vitepress" aria-label="github" target="_blank" rel="noopener" data-v-c9628203 data-v-3f83907b><span class="vpi-social-github"></span></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-f1cc7ac9 data-v-266ae973 data-v-13cdd73a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-13cdd73a><span class="vpi-more-horizontal icon" data-v-13cdd73a></span></button><div class="menu" data-v-13cdd73a><div class="VPMenu" data-v-13cdd73a data-v-782d28ee><!----><!--[--><!--[--><!----><div class="group" data-v-266ae973><div class="item appearance" data-v-266ae973><p class="label" data-v-266ae973>Appearance</p><div class="appearance-action" data-v-266ae973><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-266ae973 data-v-f9f47021 data-v-7a4da74b><span class="check" data-v-7a4da74b><span class="icon" data-v-7a4da74b><!--[--><span class="vpi-sun sun" data-v-f9f47021></span><span class="vpi-moon moon" data-v-f9f47021></span><!--]--></span></span></button></div></div></div><div class="group" data-v-266ae973><div class="item social-links" data-v-266ae973><div class="VPSocialLinks social-links-list" data-v-266ae973 data-v-c9628203><!--[--><a class="VPSocialLink no-icon" href="https://github.com/vuejs/vitepress" aria-label="github" target="_blank" rel="noopener" data-v-c9628203 data-v-3f83907b><span class="vpi-social-github"></span></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-f1cc7ac9 data-v-4d8ad16d><span class="container" data-v-4d8ad16d><span class="top" data-v-4d8ad16d></span><span class="middle" data-v-4d8ad16d></span><span class="bottom" data-v-4d8ad16d></span></span></button></div></div></div></div><div class="divider" data-v-f1cc7ac9><div class="divider-line" data-v-f1cc7ac9></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-e82b0478 data-v-8e7ffb7c><div class="container" data-v-8e7ffb7c><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-8e7ffb7c><span class="vpi-align-left menu-icon" data-v-8e7ffb7c></span><span class="menu-text" data-v-8e7ffb7c>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-8e7ffb7c data-v-6d360d95><button data-v-6d360d95>Return to top</button><!----></div></div></div><aside class="VPSidebar" data-v-e82b0478 data-v-815c4c2d><div class="curtain" data-v-815c4c2d></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-815c4c2d><span class="visually-hidden" id="sidebar-aria-label" data-v-815c4c2d> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-82ed0220><section class="VPSidebarItem level-0 has-active" data-v-82ed0220 data-v-8f293ade><div class="item" role="button" tabindex="0" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><h2 class="text" data-v-8f293ade>vue3</h2><!----></div><div class="items" data-v-8f293ade><!--[--><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/chuanzhi.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>vue-组件传值</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/keep-alive.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>keep-alive</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/Provide%20_Inject.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>Provide _Inject</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/slot.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>插槽-slot</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/Teleport.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>传送组件-Teleport</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/transition-group.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>动画-transition-group</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/transition.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>动画-transition</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/v-model.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>v-model</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/Vue-Datatype.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>Vue-定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/Vue3-Mitt.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>Vue3-Mitt</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/VUEX.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>VUEX</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/watch.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>数据监听-watch</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/ybzujian-fenbao.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>异步组件-分包</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/VUEX.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>VUEX</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/zujian.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>全局组件-局部组件</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-8f293ade data-v-8f293ade><div class="item" data-v-8f293ade><div class="indicator" data-v-8f293ade></div><a class="VPLink link link" href="/column/VueNotes/Vue3-lifecycle.html" data-v-8f293ade><!--[--><p class="text" data-v-8f293ade>Vue3生命周期</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-e82b0478 data-v-91af4e23><div class="VPDoc has-sidebar has-aside" data-v-91af4e23 data-v-fca15d40><!--[--><!--]--><div class="container" data-v-fca15d40><div class="aside" data-v-fca15d40><div class="aside-curtain" data-v-fca15d40></div><div class="aside-container" data-v-fca15d40><div class="aside-content" data-v-fca15d40><div class="VPDocAside" data-v-fca15d40 data-v-ec239fac><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-ec239fac data-v-c0dee88f><div class="content" data-v-c0dee88f><div class="outline-marker" data-v-c0dee88f></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-c0dee88f>On this page</div><ul class="VPDocOutlineItem root" data-v-c0dee88f data-v-369db6a8><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-ec239fac></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-fca15d40><div class="content-container" data-v-fca15d40><!--[--><!--]--><main class="main" data-v-fca15d40><div style="position:relative;" class="vp-doc _column_VueNotes_VUEX" data-v-fca15d40><div><h2 id="O9BzL">一.Vuex是什么？为什么要用它？</h2> vuex官方解释 <p>Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式 + 库。它采用集中式存储管理应用的所有组件的状态，并以相应的规则保证状态以一种可预测的方式发生变化。</p><p>大家可以思考一下，组件之间的传值有哪些？有父子通讯，兄弟组件通讯......但是传参对于多层嵌套就显得非常繁琐，代码维护也会非常麻烦。因此vuex就是把组件共享状态抽取出来以一个全局单例模式管理，把共享的数据函数放进vuex中，任何组件都可以进行使用。</p><h2 id="OrElt">二.什么时候我们该使用它？</h2> Vuex 可以帮助我们管理共享状态，并附带了更多的概念和框架。这需要对短期和长期效益进行权衡。 <p>如果您不打算开发大型单页应用，使用 Vuex 可能是繁琐冗余的。确实是如此——如果您的应用够简单，您最好不要使用 Vuex。一个简单的 store 模式就足够您所需了。但是，如果您需要构建一个中大型单页应用，您很可能会考虑如何更好地在组件外部管理状态，Vuex 将会成为自然而然的选择。</p><p>进行配置</p><p>新建store文件&gt;index.js 进行配置，在main.js中进行引用</p><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Vue </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;vue&#39;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Vuex </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;vuex&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">Vue.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">use</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(Vuex)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Vuex.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">Store</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  //数据，相当于data</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  state: {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    count: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">123</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">		list: [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">8</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  },</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//放置所有vuex的计算属性  </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  getters: {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  },</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  	//mutations是一个对象，对象中存放修改state的方法</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//在mutations 定义修改staate数据的方法 </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//state 指的就是当前对象vuex中state对象 在函数里面可以通过.count来获取具体的数值 </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//第二个参数 paylaod 载荷 提交mutation的方法的时候 传递的参数 可以是任何形式 任何类型的值 用来对第一个参数进行修改		</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  mutations: {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  },</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//方法</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//action 方法参数</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//context 相当于 组件中的this.$store </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  actions: {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  },</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  modules: {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  },</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">})</span></span></code></pre></div><p>核心概念</p><p>vuex中一共有五个状态 state Getter Mutation Action Module （骂洲）</p><p>State 提供唯一的公共数据 所有的共享的数据统一放到store的state进行储存，相似于data</p><p>在vue的state中进行数据的定义，可以在任何组件中进行调用</p><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Vue </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;vue&#39;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Vuex </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;vuex&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">Vue.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">use</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(Vuex)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Vuex.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">Store</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  //数据，相当于data</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  state: {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    name:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;张三&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    age:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    count:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  }</span></span></code></pre></div><p>调用方法</p><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//1.直接在标签中直接使用</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">p</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;{{$store.state.name}}&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">p</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">p</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;{{$store.state.age}}&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">p</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//2.方法二</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.$store.state.全局数据名称</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//3.从vuex中按需导入函数mapstate</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//注意当前组件需要的全局组件 映射蔚当前组件的computed属性</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">computed：{</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">  ...</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mapState</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">([</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;name&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;age&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;sex&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">])</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">p</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;{{$store.state.name}}&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">p</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">p</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;{{$store.state.age}}&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">p</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">p</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;辅助函数{{name+age+sex}}&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">p</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span></code></pre></div><p>Mutation</p><p>更改Vuex的store 中的状态的唯一方法是提交mutation。Vuex中的mutation非常类似于事件：每个mutation都有一个字符串的事件类型（type）和一个回调函数，这个回调函数就是我们实际进行状态更改的地方没并且他会接受state作为的第一个参数：</p><p>在vuex中定义</p><p>其中参数state参数都是必须要的，也可以自己传递一个参数</p><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">state：{</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  name：</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;张三&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">，</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  age：</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">，</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  count：</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">},</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getters</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:{</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">},</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//里面定义方法，操作state方法</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">mutations：{</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  addcount</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(state,num){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    state.count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> state.count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  },</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  reduce</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(state){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    state.count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">button</span><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;"> @click=&quot;btn&quot;&gt;点我增加</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> store</span><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;"> 仓库中的数据&lt;/button&gt;</span></span>
<span class="line"><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;">&lt;button</span><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;"> @click=&quot;btn1&quot;&gt;点我减少</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> store</span><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;"> 仓库中的数据&lt;/button&gt;</span></span></code></pre></div><p>方法一：注意使用commit触发Mutation操作</p><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">methods：{</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  btn</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.$store.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">commit</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;addcount&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  btn1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.$store.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">commit</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;reduce&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p>方法二： 使用辅助函数进行操作，具体方法同上</p><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">methods：{</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">  ...</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mapMutations</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">([</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;addcount&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;reduce&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]),</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  btn</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">     this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">addcount</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  },</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  btn1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">reduce</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p>Action --异步操作</p><p>Action跟Mutation相似 一般不用mutation异步操作，如果要是践行异步操作就使用Action</p><p>原因：为了方便devtools打个快照存下来，方便管理维护。所以说这个只是规范，而不是逻辑不允许，只是为了这个工具能够追踪数据变化而已</p><p>在vuex中定义</p><p>将上面的减法操作改为异步操作</p><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 操作异步操作mutation</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">actions：{</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  asyncAdd</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(context){</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">    //异步</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    seTimeout</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">       context.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">commit</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;reduce&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    },</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1000</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	mutations</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//mutations是一个对象，对象中存放修改state的方法</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//在mutations 定义修改staate数据的方法 </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//state 指的就是当前对象vuex中state对象 在函数里面可以通过.count来获取具体的数值 </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//第二个参数 paylaod 载荷 提交mutation的方法的时候 传递的参数 可以是任何形式 任何类型的值 用来对第一个参数进行修改		</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">		addCount</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(state, paylaod) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">			state.count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> paylaod</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">		}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	},</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	actions</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//方法</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//action 方法参数</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//context 相当于 组件中的this.$store </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">		getAsyncCount</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(context, params) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">			setTimeout</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">function</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">				//假设获取一个值 123 这个就是后端传递过来的值</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">				context.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">commit</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;addCount&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, params)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">			}, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1000</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">		}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	},</span></span></code></pre></div><p>在组件中使用方法</p><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//方法一 直接使用dispatch触发 Action函数</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.$store.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dispatch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;asynAdd&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//方法二 使用辅助函数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">...</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mapActions</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">([</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;asyncAdd&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]),</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">btn2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">asyncAdd</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">button</span><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;"> @click=&quot;getAsyncCount(100)&quot;&gt;+123action函数辅助的方法&lt;/button&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	</span></span>
<span class="line"><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;">...mapMutations([&#39;addCount&#39;]),</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">			</span></span>
<span class="line"><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;">...mapActions([&#39;getAsyncCount&#39;])</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //引入异步的actions</span></span></code></pre></div><p>getters:<!----></p><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	getters</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//放置所有vuex的计算属性</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">		filterList</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">state</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> state.list.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">filter</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">item</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> item </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">),</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//通过计算属性来获取modules中的数据 见下面模块处 </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">		token</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">state</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> state.user.token,</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">		name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">state</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> state.setting.name</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	},</span></span></code></pre></div><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">div</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">		函数辅助形式的getters{{filterList}}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">div</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">computed</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:{</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">			...</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mapGetters</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">([</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;filterList&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">])</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">		},</span></span></code></pre></div><p>Modules：遇见大型项目的时候，数据量大，store就会显的很臃肿</p><p>为了解决以上问题 Vuex允许我们讲store分割成模块（module）每个模块拥有自己的state，mutation，action，getter，甚至是潜逃子模块---从上之下进行同方式的分割</p><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	modules</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">		user</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">			//进行一个模块加密 加密后当前模块就无法被访问了</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">			namespaced</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">			state</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">				token</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;123435&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">			},</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">			mutations</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">				updateToken</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(state) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">					state.token </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;67890&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">				}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">			}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">		},</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">		//应用实例的名称</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">		setting</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">			state</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">				name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;vue实例&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">			}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">		}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	}</span></span></code></pre></div><div class="language-javascript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">template</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">div</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">       &lt;!--用户的token和应用名称name--&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	   &lt;!--$store.state.state.子模块.属性 的方式进行引用--&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	   &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">div</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;用户的token是{{$store.state.user.token}}&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">div</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	   &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">div</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;快捷方式：用户的token是{{token}}&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">div</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	   &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">div</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;应用实例的名称{{$store.state.setting.name}}&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">div</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	   &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">div</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;快捷方式：应用实例的名称{{name}}&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">div</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	   </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	   &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">button</span><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;"> @click=&quot;updateToken&quot;&gt;修改子模块的token&lt;/button&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	   </span></span>
<span class="line"><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;">	&lt;/div&gt;</span></span>
<span class="line"><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;">&lt;/template&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;">&lt;script&gt;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {mapGetters,createNamespacedHelpers} </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;vuex&#39;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//createNamespacedHelpers 引入模块的破解模板 直接使用 </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">const</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {mapMutations} </span><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;">=</span><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;"> createNamespacedHelpers(&#39;user&#39;)</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//直接引入mapMutations 到user模块 这样user模块及时被加密也是可以被访问的  </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">export</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> default</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//计算</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	computed:{</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">		...</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mapGetters</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">([</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;token&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;name&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">])</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	},</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//方法</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	methods:{</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">	    ...</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mapMutations</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">([</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;updateToken&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">])		</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"><span style="--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;">&lt;/script&gt;</span></span></code></pre></div></div></div></main><footer class="VPDocFooter" data-v-fca15d40 data-v-ce8ba144><!--[--><!--]--><!----><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-ce8ba144><span class="visually-hidden" id="doc-footer-aria-label" data-v-ce8ba144>Pager</span><div class="pager" data-v-ce8ba144><a class="VPLink link pager-link prev" href="/column/VueNotes/Vue3-Mitt.html" data-v-ce8ba144><!--[--><span class="desc" data-v-ce8ba144>Previous page</span><span class="title" data-v-ce8ba144>Vue3-Mitt</span><!--]--></a></div><div class="pager" data-v-ce8ba144><a class="VPLink link pager-link next" href="/column/VueNotes/watch.html" data-v-ce8ba144><!--[--><span class="desc" data-v-ce8ba144>Next page</span><span class="title" data-v-ce8ba144>数据监听-watch</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!--]--></div></div>
    <script>window.__VP_HASH_MAP__=JSON.parse("{\"api-examples.md\":\"Bx-Jd6UR\",\"column_vuenotes_chuanzhi.md\":\"Dw9eOmWg\",\"column_vuenotes_computed.md\":\"Cph73eXA\",\"column_vuenotes_index.md\":\"1DY-uiPD\",\"column_vuenotes_keep-alive.md\":\"BGwPBAxf\",\"column_vuenotes_provide _inject.md\":\"CXNB4ICa\",\"column_vuenotes_slot.md\":\"7cFP_uzl\",\"column_vuenotes_teleport.md\":\"B-CLWFVl\",\"column_vuenotes_transition-group.md\":\"xFJLsKGS\",\"column_vuenotes_transition.md\":\"BhJu4qZx\",\"column_vuenotes_v-model.md\":\"DpSGwMVZ\",\"column_vuenotes_vue-datatype.md\":\"B-VDpPCq\",\"column_vuenotes_vue3-lifecycle.md\":\"WlFlZ_Za\",\"column_vuenotes_vue3-mitt.md\":\"BsaW0WmK\",\"column_vuenotes_vuex.md\":\"HETRXYa7\",\"column_vuenotes_watch.md\":\"DtS7EOXr\",\"column_vuenotes_ybzujian-fenbao.md\":\"CaBZ22_-\",\"column_vuenotes_zujian.md\":\"lklz3ajH\",\"index.md\":\"DAYRkJ1R\",\"markdown-examples.md\":\"Dba7VhfD\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"en-US\",\"dir\":\"ltr\",\"title\":\"千里之行，始于足下\",\"description\":\"A VitePress Site\",\"base\":\"/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"logo\":\"/avatar.png\",\"nav\":[{\"text\":\"首页\",\"link\":\"/\"},{\"text\":\"前端开发\",\"items\":[{\"text\":\"vue杂记\",\"link\":\"/column/VueNotes/\"},{\"text\":\"javascript\",\"link\":\"/column/JavaScript/\"},{\"text\":\"H5C3\",\"link\":\"/column/Growing/\"},{\"text\":\"TS\",\"link\":\"/column/Growing/\"},{\"text\":\"javascript\",\"link\":\"/column/Growing/\"},{\"text\":\"暂无\",\"link\":\"/column/Growing/\"}]},{\"text\":\"服务端杂记\",\"items\":[{\"text\":\"node.js\",\"link\":\"/column/Travel/\"},{\"text\":\"数据库\",\"link\":\"/column/Growing/\"}]},{\"text\":\"关于我\",\"items\":[{\"text\":\"Gitee\",\"link\":\"https://gitee.com/akeone\"},{\"text\":\"掘金\",\"link\":\"https://juejin.cn/user/430664290931799\"}]}],\"sidebar\":{\"/column/VueNotes/\":[{\"text\":\"vue3\",\"items\":[{\"text\":\"vue-组件传值\",\"link\":\"/column/VueNotes/chuanzhi\"},{\"text\":\"keep-alive\",\"link\":\"/column/VueNotes/keep-alive\"},{\"text\":\"Provide _Inject\",\"link\":\"/column/VueNotes/Provide _Inject\"},{\"text\":\"插槽-slot\",\"link\":\"/column/VueNotes/slot\"},{\"text\":\"传送组件-Teleport\",\"link\":\"/column/VueNotes/Teleport\"},{\"text\":\"动画-transition-group\",\"link\":\"/column/VueNotes/transition-group\"},{\"text\":\"动画-transition\",\"link\":\"/column/VueNotes/transition\"},{\"text\":\"v-model\",\"link\":\"/column/VueNotes/v-model\"},{\"text\":\"Vue-定义数据类型\",\"link\":\"/column/VueNotes/Vue-Datatype\"},{\"text\":\"Vue3-Mitt\",\"link\":\"/column/VueNotes/Vue3-Mitt\"},{\"text\":\"VUEX\",\"link\":\"/column/VueNotes/VUEX\"},{\"text\":\"数据监听-watch\",\"link\":\"/column/VueNotes/watch\"},{\"text\":\"异步组件-分包\",\"link\":\"/column/VueNotes/ybzujian-fenbao\"},{\"text\":\"VUEX\",\"link\":\"/column/VueNotes/VUEX\"},{\"text\":\"全局组件-局部组件\",\"link\":\"/column/VueNotes/zujian\"},{\"text\":\"Vue3生命周期\",\"link\":\"/column/VueNotes/Vue3-lifecycle\"}]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/vuejs/vitepress\"}]},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
    
  </body>
</html>